package com.hyper_yang.javase.collections.pojo;

import java.util.Objects;

public class Student implements Comparable<Student>{
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    // TreeSet 排序规则
    @Override
    public int compareTo(Student o) {
        // 按年龄升序 this 为当前需要添加的  o 为已经存在的
        System.out.println("-------------------------------------");
        System.out.println("this: " + this);
        System.out.println("o: " + o);
        int sortByAge = this.getAge() - o.getAge();
        return sortByAge;
    }

    @Override // 不重写，默认按地址值
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name) && Objects.equals(age, student.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


}
